let ddz = {
	name: 'ddz',
	type: 'way',
	staticPath: '/static',
	names: [
		'0',
		'dA',
		'd2',
		'd3',
		'd4',
		'd5',
		'd6',
		'd7',
		'd8',
		'd9',
		'd10',
		'dJ',
		'dQ',
		'dK',
		'cA',
		'c2',
		'c3',
		'c4',
		'c5',
		'c6',
		'c7',
		'c8',
		'c9',
		'c10',
		'cJ',
		'cQ',
		'cK',
		'bA',
		'b2',
		'b3',
		'b4',
		'b5',
		'b6',
		'b7',
		'b8',
		'b9',
		'b10',
		'bJ',
		'bQ',
		'bK',
		'aA',
		'a2',
		'a3',
		'a4',
		'a5',
		'a6',
		'a7',
		'a8',
		'a9',
		'a10',
		'aJ',
		'aQ',
		'aK',
		'X',
		'D'
	],
	$game: null
};

ddz.sound = function(type) {
	var filename;
	if (type == '要不起') {
		filename = 'buyao1';
	} else if (type == '叫地主') {
		filename = 'Order';
	} else if (type == '不叫') {
		filename = 'NoOrder';
	} else if (type == '抢地主') {
		filename = 'Rob1';
	} else if (type == '不抢') {
		filename = 'NoRob';
	} else if (type == '加倍') {
		filename = 'jiabei';
	} else if (type == '不加倍') {
		filename = 'bujiabei';
	} else if (type == '一张牌') {
		filename = 'baojing1';
	} else if (type == '两张牌') {
		filename = 'baojing2';
	} else if (type == '胜利') {
		filename = 'music/win';
	} else if (type == '失败') {
		filename = 'music/lose';
	}
	console.log(`sound：${filename}`, type);
	if (filename) {
		onez.vue.playSound(filename + '.ogg');
	}
};
ddz.speak = function(cards) {
	var type = ddz.cardsType(cards);
	var filename;
	var name = cards[0].name;
	if (name == 'A') {
		name = '1';
	} else if (name == 'J') {
		name = '11';
	} else if (name == 'Q') {
		name = '12';
	} else if (name == 'K') {
		name = '13';
	} else if (name == 'X') {
		name = '14';
	} else if (name == 'D') {
		name = '15';
	}
	if (type == '单牌') {
		var value = name;
		filename = value;
	} else if (type == '对牌') {
		var value = name;
		filename = 'dui' + value;
	} else if (type == '三张牌') {
		var value = name;
		filename = 'tuple' + value;
	} else if (type == '火箭') {
		filename = 'wangzha';
	} else if (type == '炸弹') {
		filename = 'zhadan';
	} else if (type == '单顺') {
		filename = 'shunzi';
	} else if (type == '双顺') {
		filename = 'liandui';
	} else if (type == '三顺') {
		filename = 'shunzi';
	} else if (type == '三带一张牌') {
		filename = 'sandaiyi';
	} else if (type == '三带一对牌') {
		filename = 'sandaiyidui';
	} else if (type == '四带二') {
		filename = 'sidaier';
	} else if (type == '飞机带翅膀') {
		filename = 'feiji';
	}
	console.log(`speak：${filename}`, type);
	if (filename) {
		ddz.$game.playSound(ddz.staticPath + '/sound/Woman/Woman_' + filename + '.ogg');
	}
};
ddz.sound = function(type) {
	var filename;
	if (type == '要不起') {
		filename = 'buyao1';
	} else if (type == '叫地主') {
		filename = 'Order';
	} else if (type == '不叫') {
		filename = 'NoOrder';
	} else if (type == '抢地主') {
		filename = 'Rob1';
	} else if (type == '不抢') {
		filename = 'NoRob';
	} else if (type == '加倍') {
		filename = 'jiabei';
	} else if (type == '不加倍') {
		filename = 'bujiabei';
	} else if (type == '一张牌') {
		filename = 'baojing1';
	} else if (type == '两张牌') {
		filename = 'baojing2';
	} else if (type == '胜利') {
		filename = 'music/win';
		ddz.$game.playSound(ddz.staticPath + '/sound/' + filename + '.ogg');
		return;
	} else if (type == '失败') {
		filename = 'music/lose';
		ddz.$game.playSound(ddz.staticPath + '/sound/' + filename + '.ogg');
		return;
	}
	console.log(`sound：${filename}`, type);
	if (filename) {
		ddz.$game.playSound(ddz.staticPath + '/sound/Woman/Woman_' + filename + '.ogg');
	}
};
ddz.playSound = async function(that, request) {
	if (request.cards) {
		ddz.speak(ddz.toArray(request.cards));
	} else if (request.type) {
		ddz.sound(request.type);
	}
};
//启动游戏
ddz.start = async function(that, request) {
	return {
		ui: [],
		scene: 'room'
	};
};
//当前场景
ddz.scene = async function(that, request) {
	if (request['sceneName'] == 'room') { //游戏房间
		return {
			pic: ddz.staticPath + '/images/ui/bg2.png',
			music: ddz.staticPath + '/sound/music/playing.ogg',
			credit_base: 0,
			mode: 'full',
		};
	}
};
//加载角色信息
ddz.player = async function(that, request) {
	return {
		role: {
			status: 'normal'
		}
	};
};
ddz.toArray = function(o) {
	console.log('toArray ===> ', o)
	if (!o) {
		return []
	}
	let cards = [];
	let color = ['黑桃', '红桃', '梅花', '方块'];
	let colorKeys = ['a', 'b', 'c', 'd'];
	let number = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2', 'X', 'D'];
	for (var i = 0; i < o.length; i++) {
		var card = {
			name: o[i],
			key: o[i],
			color: '',
			value: -1
		};
		if (o[i].length >= 2) {
			var c = o[i].substr(0, 1);
			card.name = o[i].substr(1);
			card.color = color[colorKeys.indexOf(c)];
		}
		card.value = number.indexOf(card.name) + 1;
		cards.push(card);
	}
	return cards;
};
ddz.toKeys = async function(that, request) {
	let keys = [];
	(request ? request['cards'] : that).forEach(card => {
		keys.push(card.key || card.name);
	});
	return keys;
};
ddz.orderBy = function(cards, keys, orderby) {
	cards.sort(function(a, b) {
		var key = keys[0];
		if (orderby[0] == 'desc') {
			return b[key] - a[key];
		} else {
			return a[key] - b[key];
		}
	});
	return cards;
};
ddz.sortBy = function(arr) {
	arr.sort(function(a, b) {
		return a - b
	});
	return arr;
};
ddz.cardsType = function(cards) {
	if (cards.length == 1)
		return '单牌'
	if (cards.length == 2 && cards[0].value >= 14 && cards[1].value >= 14)
		return '火箭'

	cards = ddz.orderBy(cards, ['value'], ['desc'])
	let arr = []
	let cnt = 1
	let flag = true //判断顺牌
	for (var i = 0; i < cards.length; i++) {
		if (i < cards.length - 1 && cards[i].value == cards[i + 1].value)
			cnt++
		else {
			if ((arr.length > 0 && cnt != arr[arr.length - 1]) ||
				cards[i].value >= 13 || cards.length < 5)
				flag = false
			arr.push(cnt)
			cnt = 1
		}
	}

	if (flag) {
		if (arr[0] == 1 && arr.length >= 5) {
			let r = true
			for (var i = 0; i < cards.length; i++) {
				if (i < cards.length - 1) {
					if (cards[i].value - cards[i + 1].value != 1) {
						r = false
					}
				}
			}
			if (r)
				return '单顺'
		} else if (arr[0] == 2 && arr.length >= 3) {
			let r = true
			for (var i = 0; i < cards.length; i = i + 2) {
				if (i < cards.length - 2) {
					if (cards[i].value - cards[i + 2].value != 1) {
						r = false
					}
				}
			}
			if (r)
				return '双顺'
		} else if (arr[0] == 3 && arr.length >= 2) {
			let r = true
			for (var i = 0; i < cards.length; i = i + 3) {
				if (i < cards.length - 3) {
					if (cards[i].value - cards[i + 3].value != 1) {
						r = false
					}
				}
			}
			if (r)
				return '三顺'
		}
	} else {
		arr = ddz.sortBy(arr)
		if (arr.length == 1) {
			if (arr[0] == 2)
				return '对牌'
			else if (arr[0] == 3)
				return '三张牌'
			else if (arr[0] == 4)
				return '炸弹'
		} else if (arr.length == 2) {
			if (arr[0] == 1 && arr[1] == 3)
				return '三带一张牌'
			else if (arr[0] == 2 && arr[1] == 3)
				return '三带一对牌'
		} else if (arr.length == 3) {
			if ((arr[0] == 1 && arr[1] == 1 && arr[2] == 4) ||
				(arr[0] == 2 && arr[1] == 2 && arr[2] == 4))
				return '四带二'
		} else if (arr.length >= 4) {
			if (arr.length % 2 == 0) {
				let flag = true
				for (var i = 0; i < arr.length / 2; i++) {
					if ((i < arr.length / 2 - 1 && arr[i] != arr[i + 1]) ||
						(arr[i] != 1 && arr[i] != 2))
						flag = false
				}
				for (var i = arr.length / 2; i < arr.length; i++) {
					if (arr[i] != 3)
						flag = false
				}
				if (flag)
					return '飞机带翅膀'
			}
		}
	}
	return null
};
ddz.numArray = function(cards) {
	var newCards = [];
	for (var i = 0; i < cards.length; i++) {
		for (var j = 0; j < cards[i].length; j++) {
			newCards.push(cards[i][j]);
		}
	}
	return newCards;
};
ddz.remainCards = function(that, request) {
	var remain = [];
	for (var i = 0; i < request['myCards'].length; i++) {
		if (request['outCards'].indexOf(request['myCards'][i]) == -1) {
			remain.push(request['myCards'][i]);
		}
	}
	return remain;
};
ddz.getCardsType = function(that, request) {
	let {
		cards
	} = request;
	cards = ddz.toArray(cards);
	return ddz.cardsType(cards)
}
ddz.canChupai = function(that, request) {
	let {
		cards,
		curCards
	} = request;
	cards = ddz.toArray(cards);
	curCards = ddz.toArray(curCards);


	var type1 = ddz.cardsType(cards)
	console.log(`点击选择的纸牌：${type1}`)
	var type2 = ddz.cardsType(curCards)
	console.log(`桌面上已有牌型：${type2}`)
	if (cards.length > 0 && curCards.length > 0) {
		if (type1 != type2) { //牌型不同
			if (!(type1 == '火箭' || (type1 == '炸弹' && type2 != '火箭'))) {
				console.log(`牌型不同`)
				return 2
			}
		} else { //牌型相同
			if (type1 == '单牌' || type1 == '对牌' || type1 == '三张牌' || type1 == '炸弹') {
				if (cards[0].value <= curCards[0].value) {
					console.log(`分值小于等于牌桌上的牌`)
					return 1
				}
			}
			if (cards.length != curCards.length) {
				console.log(`总张数不同`)
				return 2
			} else {
				cards = ddz.orderBy(cards, ['value'], ['desc'])
				curCards = ddz.orderBy(curCards, ['value'], ['desc'])

				if (type1 == '单顺' || type1 == '双顺' || type1 == '三顺') {
					if (cards[0].value <= curCards[0].value) {
						console.log(`分值小于等于牌桌上的牌`)
						return 1
					}
				} else if (type1 == '三带一张牌' || type1 == '三带一对牌') {
					var mark = {}
					var x = 0
					var y = 0
					for (var i = 0; i < cards.length; i++) {
						if (!mark[cards[i].value])
							mark[cards[i].value] = 1
						else
							mark[cards[i].value]++
						if (mark[cards[i].value] == 3)
							x = cards[i].value
					}
					for (var i = 0; i < curCards.length; i++) {
						if (!mark[curCards[i].value])
							mark[curCards[i].value] = 1
						else
							mark[curCards[i].value]++
						if (mark[curCards[i].value] == 3)
							y = curCards[i].value
					}
					if (x <= y) {
						console.log(`分值小于等于牌桌上的牌`)
						return 1
					}
				} else if (type1 == '四带二') {
					var mark = {}
					var x = 0
					var y = 0
					for (var i = 0; i < cards.length; i++) {
						if (!mark[cards[i].value])
							mark[cards[i].value] = 1
						else
							mark[cards[i].value]++
						if (mark[cards[i].value] == 4)
							x = cards[i].value
					}
					for (var i = 0; i < curCards.length; i++) {
						if (!mark[curCards[i].value])
							mark[curCards[i].value] = 1
						else
							mark[curCards[i].value]++
						if (mark[curCards[i].value] == 4)
							y = curCards[i].value
					}
					if (x <= y) {
						console.log(`分值小于等于牌桌上的牌`)
						return 1
					}
				} else if (type1 == '飞机带翅膀') {
					var mark = {}
					var max1 = 0
					var max2 = 0
					for (var i = 0; i < cards.length; i++) {
						if (!mark[cards[i].value])
							mark[cards[i].value] = 1
						else
							mark[cards[i].value]++
						if (mark[cards[i].value] == 3) {
							if (cards[i].value > max1)
								max1 = cards[i].value
						}
					}
					for (var i = 0; i < curCards.length; i++) {
						if (!mark[curCards[i].value])
							mark[curCards[i].value] = 1
						else
							mark[curCards[i].value]++
						if (mark[curCards[i].value] == 3) {
							if (curCards[i].value > max2)
								max2 = curCards[i].value
						}
					}
					if (max1 <= max2) {
						console.log(`分值小于等于牌桌上的牌`)
						return 1
					}
				}
			}
		}
	}
	return 0;
};
//自动出牌
ddz.autoPlay = function(that, request) {
	let baseCards = request['myCards'];
	var cards = ddz.orderBy(ddz.toArray(request['myCards']), ['value'], ['asc'])
	var obj = {};
	for (var i = 0; i < cards.length; i++) {
		if (typeof obj[cards[i].value] == 'undefined') {
			obj[cards[i].value] = [cards[i]];
		} else {
			obj[cards[i].value].push(cards[i]);
		}
	}
	var nums = {
		1: [],
		2: [],
		3: [],
		4: []
	};
	for (var k in obj) {
		nums[obj[k].length].push(obj[k]);
	}
	var numCards = {};
	for (var k in nums) {
		numCards[k] = ddz.numArray(nums[k]);
	}
	//找出能管的牌
	let curCards = request['curCards'];
	if (curCards) {
		curCards = ddz.toArray(request['curCards']);
		var obj2 = {};
		for (var i = 0; i < curCards.length; i++) {
			if (typeof obj2[curCards[i].value] == 'undefined') {
				obj2[curCards[i].value] = [curCards[i]];
			} else {
				obj2[curCards[i].value].push(curCards[i]);
			}
		}
		var curNums = {
			1: [],
			2: [],
			3: [],
			4: []
		};
		for (var k in obj2) {
			curNums[obj2[k].length].push(obj2[k]);
		}

		curCards = ddz.orderBy(curCards, ['value'], ['asc'])
		var type = ddz.cardsType(curCards)
		console.log(`桌面上已有牌型：${type}`, curCards);
		var outCards;
		if (type == '火箭') {} else if (type == '炸弹') {
			var myCards = nums[4];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value > curCards[0].value) {
					outCards = myCards[i];
					break;
				}
			}
		} else if (type == '单牌') {
			var myCards = nums[1];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value > curCards[0].value) {
					outCards = myCards[i];
					break;
				}
			}
		} else if (type == '对牌') {
			var myCards = nums[2];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value > curCards[0].value) {
					outCards = myCards[i];
					break;
				}
			}
		} else if (type == '三张牌') {
			var myCards = nums[3];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value > curCards[0].value) {
					outCards = myCards[i];
					break;
				}
			}
		} else if (type == '单顺') {
			var myCards = nums[1];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curCards[0].value) {
					continue;
				}
				if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
					tmpCards.push(myCards[i][0]);
				} else {
					tmpCards = [myCards[i][0]];
				}
				if (tmpCards.length == curCards.length) {
					outCards = tmpCards;
					break;
				}
			}
		} else if (type == '双顺') {
			var myCards = nums[2];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curCards[0].value) {
					continue;
				}
				if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
					tmpCards.push(myCards[i][0]);
					tmpCards.push(myCards[i][1]);
				} else {
					tmpCards = [myCards[i][0], myCards[i][1]];
				}
				if (tmpCards.length == curCards.length) {
					outCards = tmpCards;
					break;
				}
			}
		} else if (type == '三顺') {
			var myCards = nums[3];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curCards[0].value) {
					continue;
				}
				if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
					tmpCards.push(myCards[i][0]);
					tmpCards.push(myCards[i][1]);
					tmpCards.push(myCards[i][2]);
				} else {
					tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2]];
				}
				if (tmpCards.length == curCards.length) {
					outCards = tmpCards;
					break;
				}
			}
		} else if (type == '三带一张牌') {
			var myCards = nums[3];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curNums[3][0][0].value) {
					continue;
				}
				tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2]];
				if (nums[1].length >= 1) {
					tmpCards.push(nums[1][0][0]);
					outCards = tmpCards;
				}
				break;
			}
		} else if (type == '三带一对牌') {
			var myCards = nums[3];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curNums[3][0][0].value) {
					continue;
				}
				if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
					tmpCards.push(myCards[i][0]);
					tmpCards.push(myCards[i][1]);
					tmpCards.push(myCards[i][2]);
				} else {
					tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2]];
				}
				if (nums[2].length >= 1) {
					tmpCards.push(nums[2][0][0]);
					tmpCards.push(nums[2][0][1]);
					outCards = tmpCards;
				}
				break;
			}
		} else if (type == '四带二') {
			var myCards = nums[4];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curNums[4][0].value) {
					continue;
				}
				tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2], myCards[i][3]];
				if (curNums[2].length == 2) {
					if (nums[2].length >= 2) {
						tmpCards.push(nums[2][0][0]);
						tmpCards.push(nums[2][0][1]);
						tmpCards.push(nums[2][1][0]);
						tmpCards.push(nums[2][1][1]);
						outCards = tmpCards;
					}
				} else if (curNums[1].length == 2) {
					if (nums[1].length >= 2) {
						tmpCards.push(nums[1][0][0]);
						tmpCards.push(nums[1][1][0]);
						outCards = tmpCards;
					}
				}
				break;
			}
		} else if (type == '飞机带翅膀') {
			var myCards = nums[3];
			var tmpCards = [];
			for (var i = 0; i < myCards.length; i++) {
				if (myCards[i][0].value >= 12) {
					break;
				}
				if (myCards[i][0].value < curNums[3][0].value) {
					continue;
				}
				if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
					tmpCards.push(myCards[i][0]);
					tmpCards.push(myCards[i][1]);
					tmpCards.push(myCards[i][2]);
				} else {
					tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2]];
				}
				if (tmpCards.length == curNums[3].length * 3) {
					if (curNums[2].length == curNums[3].length) {
						if (nums[2].length >= curNums[3].length) {
							for (var n = 0; n < nums[2].length; n++) {
								tmpCards.push(nums[2][n][0]);
								tmpCards.push(nums[2][n][1]);
							}
							outCards = tmpCards;
						}
					} else if (curNums[1].length == curNums[3].length) {
						if (nums[1].length >= curNums[3].length) {
							for (var n = 0; n < nums[1].length; n++) {
								tmpCards.push(nums[1][n][0]);
							}
							outCards = tmpCards;
						}
					}
					break;
				}
			}
		}
		if (!outCards) {
			if (type != '炸弹' && nums[4].length > 0) {
				if (cards.length < 6 || curNums[1].length >= 5 || curNums[2].length >= 3 || curNums[2].length >=
					2) {
					outCards = nums[4][0];
				}
			} else if (nums[1].length >= 2 && nums[1][nums[1].length - 2][0].value >= 14) { //有王炸
				if (cards.length < 6) {
					outCards = [nums[1][nums[1].length - 2][0], nums[1][nums[1].length - 1][0]];
				}
			}
		}
		return outCards;
	}

	//是否顺子
	if (nums[1].length >= 5) {
		var myCards = nums[1];
		var tmpCards = [];
		for (var i = 0; i < myCards.length; i++) {
			if (myCards[i][0].value >= 12) {
				break;
			}
			if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
				tmpCards.push(myCards[i][0]);
			} else {
				tmpCards = [myCards[i][0]];
			}
		}
		if (tmpCards.length >= 5) {
			console.log('单顺', tmpCards);
			return tmpCards;
		}
	}
	if (nums[2].length >= 3) {
		var myCards = nums[2];
		var tmpCards = [];
		for (var i = 0; i < myCards.length; i++) {
			if (myCards[i][0].value >= 12) {
				break;
			}
			if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
				tmpCards.push(myCards[i][0]);
				tmpCards.push(myCards[i][1]);
			} else {
				tmpCards = [myCards[i][0], myCards[i][1]];
			}
		}
		if (tmpCards.length >= 6) {
			console.log('双顺', tmpCards);
			return tmpCards;
		}
	}
	if (nums[3].length >= 2) {
		var myCards = nums[3];
		var tmpCards = [];
		for (var i = 0; i < myCards.length; i++) {
			if (myCards[i][0].value >= 12) {
				break;
			}
			if (tmpCards.length == 0 || myCards[i - 1][0].value + 1 == myCards[i][0].value) {
				tmpCards.push(myCards[i][0]);
				tmpCards.push(myCards[i][1]);
				tmpCards.push(myCards[i][2]);
			} else {
				tmpCards = [myCards[i][0], myCards[i][1], myCards[i][2]];
			}
		}
		if (tmpCards.length >= 6) {
			var num = tmpCards.length / 3;
			if (nums[2].length >= num) {
				for (var n = 0; n < num; n++) {
					tmpCards.push(nums[2][n][0]);
					tmpCards.push(nums[2][n][1]);
				}
				console.log('飞机', tmpCards);
			} else if (nums[1].length >= num) {
				for (var n = 0; n < num; n++) {
					tmpCards.push(nums[1][n][0]);
				}
				console.log('飞机', tmpCards);
			} else if (nums[2].length >= 1) {
				tmpCards.push(nums[2][0][0]);
				tmpCards.push(nums[2][0][1]);
				console.log('三带一对牌', tmpCards);
			} else if (nums[1].length >= 1) {
				tmpCards.push(nums[1][0][0]);
				console.log('三带一张牌', tmpCards);
			} else {
				console.log('三顺', tmpCards);
			}
			return tmpCards;
		}
	}
	if (nums[4].length >= 2 && (nums[1].length >= 2 || nums[2].length >= 2)) {
		var tmpCards = nums[4][0];
		if (nums[2].length >= 2) {
			tmpCards.push(nums[2][0][0]);
			tmpCards.push(nums[2][0][1]);
			tmpCards.push(nums[2][1][0]);
			tmpCards.push(nums[2][1][1]);
		} else if (nums[1].length >= 2) {
			tmpCards.push(nums[2][0][0]);
			tmpCards.push(nums[2][1][0]);
		}
	}
	var myCards = [];
	if (nums[1].length >= 1) {
		myCards.push({
			num: 1,
			cards: [nums[1][0][0]]
		});
	}
	if (nums[2].length >= 1) {
		myCards.push({
			num: 2,
			cards: [nums[2][0][0], nums[2][0][1]]
		});
	}
	if (nums[3].length >= 1) {
		myCards.push({
			num: 3,
			cards: [nums[3][0][0], nums[3][0][1], nums[3][0][2]]
		});
	}
	if (myCards.length > 0) {
		myCards.sort(function(a, b) {
			return a.cards[0].value - b.cards[0].value
		});
		console.log('单', myCards[0].num, myCards[0].cards);
		return myCards[0].cards;
	}
	if (nums[4].length >= 1) {
		console.log('炸弹', [nums[4][0][0], nums[4][0][1], nums[4][0][2], nums[4][0][3]]);
		return [nums[4][0][0], nums[4][0][1], nums[4][0][2], nums[4][0][3]];
	}
	return [cards[0]];
};
//智能加载素材资源
var cacheRes = {};
import dh from './dlg-header.json'
import dbtn from './dlg-quit.json'
import dbody from './dlg-body.json'
import btn1 from './btn1.json'
ddz.res = async function(that, request) {
	var hash = ddz.$game.md5(JSON.stringify(request));
	if (!cacheRes[hash]) {
		if (request.resid && request.resid == 'dlgHeader') {
			cacheRes[hash] = {
				...dh
			}
		} else if (request.resid && request.resid == 'dlgQuit') {
			cacheRes[hash] = {
				...dbtn
			}
		} else if (request.resid && request.resid == 'dlgBody') {
			cacheRes[hash] = {
				...dbody
			}
		} else if (request.resid && request.resid == 'btn1') {
			cacheRes[hash] = {
				...btn1
			}
		} else {
			cacheRes[hash] = await ddz.$game.call('res', request);
		}
	}
	return cacheRes[hash];
};

ddz.card2object = async function(that, request) {

	var cards = [];
	for (var i = 0; i < request.cards.length; i++) {
		var card = request.cards[i];
		if (card) {
			var index = ddz.names.indexOf(card) + '';
			if (index.length < 2) {
				index = '0' + index;
			}
			cards.push({
				name: card,
				selected: false,
				image: ddz.staticPath + '/images/cards/card_' + index + '.png',
			});
		} else {
			cards.push({
				name: card,
				selected: false,
				image: ddz.staticPath + '/images/cards/card_00.png',
			});
		}
	}
	return cards;
};
//洗牌
ddz.allCards = async function(that, request) {
	let colorKeys = ['a', 'b', 'c', 'd'];
	let number = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
	var cards = ['X', 'D'];
	for (var i = 0; i < colorKeys.length; i++) {
		for (var j = 0; j < number.length; j++) {
			cards.push(colorKeys[i] + number[j]);
		}
	}
	cards.sort(function() {
		return Math.random() - 0.5;
	});
	return cards;
};
//静态资源
ddz.static = async function(that, request) {
	return ddz.staticPath + request.file;
};
//用户信息
ddz.user = async function(that, request) {
	let user = {};
	user.userid = request.userid;
	user.avatar = ddz.staticPath + '/images/ui/farmer_face_to_right.png';
	user.credit = 6200103;
	if (user.userid == 'me') {
		user.nickname = '我';
	} else {
		user.nickname = user.userid;
	}
	return user;
};

export default ddz;